from manim import *

class QuadraticSurface(ThreeDScene):
    def construct(self):
        resolution_fa = 24 #曲面样本数
        axes = ThreeDAxes() #3维度笛卡尔直角坐标系
        self.set_camera_orientation(phi = 75*DEGREES, theta = 45*DEGREES) #phi是竖直方向岔开的角度，theta是水平面岔开的角度
    
        def paramsFunc(u, v): #参数方程

            x =  np.sinh(u)*np.cos(v)
            y =  np.sinh(u)*np.sin(v)
            z =  np.cosh(u)
            return np.array([x, y, z])

        quadratic_surface = Surface(
            paramsFunc,
            resolution = (resolution_fa, resolution_fa), #分辨率
            u_range=[-1.5, +1.5], #参数u的范围
            v_range=[-PI, +PI], #参数v的范围
            fill_opacity = 0.5 #透明度

        ) #二次曲面


        def paramsFunc1(u, v): #参数方程

            x =  np.sinh(u)*np.cos(v)
            y =  np.sinh(u)*np.sin(v)
            z =  np.cosh(u)
            return np.array([x, y, -z])
        
        quadratic_surface1 = Surface(
                paramsFunc1,
                resolution = (resolution_fa, resolution_fa), #分辨率
                u_range=[-1.5, +1.5], #参数u的范围
                v_range=[-PI, +PI], #参数v的范围
                fill_opacity = 0.5 #透明度

            ) #二次曲面


        self.add(axes) #添加坐标轴
        self.wait() #停留一秒
        self.play(Write(quadratic_surface), run_time = 10) #绘制二次曲面
        self.play(Write(quadratic_surface1), run_time = 10) #绘制二次曲面
        self.begin_3dillusion_camera_rotation(rate = 2) #摇晃rotation illusion
        self.wait(PI) #摇晃时长
        self.stop_3dillusion_camera_rotation() #停止摇晃

with tempconfig({'quality':'medium_quality', 'preview':True}):
    scene = QuadraticSurface()
    scene.render()